package com.up360.rapidcalc.aerolite.controller
{
    import com.up360.rapidcalc.aerolite.consts.MyGlobal;
    import com.up360.rapidcalc.aerolite.model.Barrel;
    import com.up360.rapidcalc.aerolite.model.Form;
    import com.up360.rapidcalc.aerolite.model.Fort;
    
    import flash.display.Stage;
    import flash.events.MouseEvent;
    import flash.geom.Point;

    /**
     * @author Tunie
     * @date   May 6, 2013
     */
    public class FortCtrl extends BasicCtrl
    {
        
        public function FortCtrl()
        {
            super();
        }
        
        override public function clear():void
        {
            super.clear();
            //
            parseCtrl();
        }
        
        override public function control():void
        {
            super.control();
            //
            trace(MyGlobal.stage);
            MyGlobal.stage.addEventListener(MouseEvent.MOUSE_MOVE,stageMouseMove);
        }
        
        override public function parseCtrl():void
        {
            super.parseCtrl();
            //
            MyGlobal.stage.removeEventListener(MouseEvent.MOUSE_MOVE,stageMouseMove);
        }
        /**
         * @param event
         * 
         */
        protected function stageMouseMove(event:MouseEvent):void
        {
            var b_mLocal:Point=new Point(event.stageX,event.stageY);
            var b_bLocal:Point=new Point(target.x,target.y);
            //斜边
            var b_Hypotenuse:Number=Point.distance(b_mLocal,b_bLocal);
            //直边
            var b_straightEdge:Number=b_mLocal.x-b_bLocal.x;
            var b_sin:Number=Math.asin(b_straightEdge/b_Hypotenuse);
            //根据上一步所的角度调整炮管
            (target as Fort).barrel.ui.rotation=b_sin*180/Math.PI;
        }        
        
    }
}